package com.towerdefence;

//wojtek test
//update test nauka
//
//pawel
//dupa
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.BaseActivity;
import org.andengine.ui.activity.BaseGameActivity;

import android.view.Display;

//dupa
public class MainActivity extends BaseGameActivity { //glowna aktywnosc

	
 
    public int CAMERA_WIDTH = 854;
    public int CAMERA_HEIGHT = 480;

    public Font mFont; //czcionka do pisania na ekranie
    public Camera mCamera ;//uchwyt do kamery
    public Scene mCurrentScene; //uchwyt do obecnie aktywnej sceny
    public static BaseActivity instance; //?
    
 
///BITMAPY


	//public BitmapTextureAtlas Atlas2; 
	//public TextureRegion Region2;
   
    public BitmapTextureAtlas start_A,fastplay_A,exit_A; 
	public TextureRegion start_T,fastplay_T,exit_T;
    
    @SuppressWarnings("deprecation")
	@Override
    public EngineOptions onCreateEngineOptions() {
     
    	 
        final Display display = getWindowManager().getDefaultDisplay();
        CAMERA_WIDTH = display.getWidth();
        CAMERA_HEIGHT = display.getHeight();
    	
        mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        instance = this;
        
    
        EngineOptions silnik =  new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,//+down
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera); //to jest jedna linia! 
        silnik.getAudioOptions().setNeedsMusic(true);
        return silnik;
        
    	
        
        
    }
    
    

    
  

    protected void onCreateResourcesmoje() { //tu zalaczam wszystkie zasoby
    	System.gc();//garbage collector
    	
    	FontFactory.setAssetBasePath("Fonts/"); //ustawiam sciezke dla czcionek w folderze Assets/Fonts/
    	BitmapTextureAtlas mDroidFontTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    	
    	
    
      	  
    	  BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");//ustawiam sciezke dla plikow grafiki Assets/gfx/

    	//  Atlas2 = new BitmapTextureAtlas(this.getTextureManager(),1024, 1024, TextureOptions.DEFAULT);
    	//  Region2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.Atlas2, this, "File2.png", 0, 0);
    	//  Atlas2.load();  
    	  start_A = new BitmapTextureAtlas(this.getTextureManager(),1024, 1024, TextureOptions.DEFAULT);
    	  start_T = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.start_A, this, "start.png", 0, 0);
    	  start_A.load(); 
    	
    	  fastplay_A = new BitmapTextureAtlas(this.getTextureManager(),1024, 1024, TextureOptions.DEFAULT);
    	  fastplay_T = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.fastplay_A, this, "fastplay.png", 0, 0);
    	  fastplay_A.load(); 
    	  
       	  exit_A = new BitmapTextureAtlas(this.getTextureManager(),1024, 1024, TextureOptions.DEFAULT);
    	  exit_T = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.exit_A, this, "exit.png", 0, 0);
    	  exit_A.load(); 
    	  
    }


    
 
    
    
    protected Scene onCreateScenemoje() {
        return mCurrentScene;
    }
    
    
    
   
    
    
    public static MainActivity getSharedInstance() //do pobierania instancji aktywnosci z niej mozesz sie odwolywac do kazdego obiektu
    {
        return (MainActivity) instance;
    }

    public void setCurrentScene(Scene scene) {//zmienia aktywn¹ scenê
    	mCurrentScene = scene;
        getEngine().setScene(mCurrentScene);
    }
  


    
	@Override
	public void onCreateResources(
			OnCreateResourcesCallback pOnCreateResourcesCallback)
			throws Exception {
		onCreateResourcesmoje();
		pOnCreateResourcesCallback.onCreateResourcesFinished();
		
	}


	@Override
	public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
			throws Exception {
		
		mCurrentScene = new Menu();
		
		 pOnCreateSceneCallback.onCreateSceneFinished(mCurrentScene);
	}


	@Override
	public void onPopulateScene(Scene pScene,
			OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
		 pOnPopulateSceneCallback.onPopulateSceneFinished();
	}

}
